import React, { useState, useEffect } from 'react'

export default function Test() {
  const [count, setCount] = useState(10)
  useEffect(() => {
    const timer = setInterval(() => {
      // !如何实时拿到变化后的 count
      setCount((count) => count - 1)
    }, 1000)
    return () => {
      // useEffect 第二个参数为空数组
      // 执行时机：组件卸载的时候，类似类中 componentWillUnMount
      clearInterval(timer)
    }
  }, [])

  useEffect(() => {
    // count 变化后会执行
    console.log(count)
  }, [count])
  return (
    <div>
      <h3>{count}</h3>
    </div>
  )
}
